// server/utils/seed.js
import mongoose from "mongoose";
import User from "../models/User.js";
import { hashPassword } from "../utils/bcrypt.js";

mongoose
  .connect("mongodb://localhost:27017/nebula")
  .then(async () => {
    console.log("🟢 数据库连接成功, 开始插入测试用户");

    const users = [
      { name: "admin", password: await hashPassword("123456"), isActive: true },
      { name: "user1", password: await hashPassword("user123"), isActive: false },
    ];

    await User.insertMany(users);
    console.log(`🟢 成功插入 ${users.length} 条测试用户数据`);

    process.exit();
  })
  .catch((err) => {
    console.error("❌ 连接失败：", err);
    process.exit(1);
  });
